"""Rules/toolchains to use browsers with Bazel."""

module(
    name = "rules_browsers",
    version = "0.1.0",
)

# Load browsers for tests.
browsers = use_extension("//browsers:extensions.bzl", "browsers")
browsers.chrome()
browsers.chromedriver()
browsers.firefox()
use_repo(
    browsers,
    "rules_browsers_chrome_linux",
    "rules_browsers_chrome_mac",
    "rules_browsers_chrome_mac_arm",
    "rules_browsers_chromedriver_linux",
    "rules_browsers_chromedriver_mac",
    "rules_browsers_chromedriver_mac_arm",
    "rules_browsers_firefox_linux",
    "rules_browsers_firefox_mac",
    "rules_browsers_firefox_mac_arm",
)

# Miscellaneous dependencies.
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "bazel_skylib", version = "1.8.1")

# Manually specify a recent Node.js version.
bazel_dep(name = "rules_nodejs", version = "6.5.0")

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "22.18.0")

# JS
bazel_dep(name = "aspect_rules_js", version = "2.4.2")

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")
npm.npm_translate_lock(
    name = "npm_rules_browsers",
    data = [
        "//:package.json",
        "//:patches/@web__test-runner-chrome@0.18.0.patch",
    ],
    npmrc = "//:.npmrc",
    pnpm_lock = "//:pnpm-lock.yaml",
    verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm_rules_browsers")

# TS
bazel_dep(name = "aspect_rules_ts", version = "3.6.3")

rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext")
rules_ts_ext.deps(
    ts_version_from = "//:package.json",
)
use_repo(rules_ts_ext, "npm_typescript")
